use yew::prelude::*;
use yew_router::prelude::*;

use crate::{
  components::login_form::LoginForm, contexts::CurrentUserContext, Route,
};

#[function_component]
pub fn Login() -> Html {
  let current_user_ctx = use_context::<CurrentUserContext>()
    .expect("Current user context is missing");

  match &current_user_ctx.user {
    Some(_) => {
      html! {
        <Redirect<Route> to={Route::Home}/>
      }
    }
    None => {
      html! {
        <>
          <img src="./logo.svg" alt="logo"/>
          <LoginForm/>
        </>
      }
    }
  }
}
